<template>
  <el-select v-model="packUnit" @change="getUnit">
    <el-option v-for="its in lotNumberList" :key="its.id" :value="its.id" :label="its.desc"></el-option>
  </el-select>
</template>
<script>
export default {
  props: ["value", "unit", "list", "type"],
  data() {
    return {
      packUnit: "",
      lotNumberList: []
    };
  },
  mounted() {
    this.packUnit = this.unit;
    this.getBasic();
  },
  methods: {
    getBasic() {
      const th = this;
      if (th.type == 1) {
        th.getCommonConfigByKey("单位").then(res => {
          let l = res;
          let _item = [];
          for (let i = 0; i < l.length; i++) {
            let arr = {};
            for (let j = 0; j < th.list.length; j++) {
              if (l[i].id == th.list[j]) {
                arr = l[i];
                _item.push(arr);
              }
            }
          }
          th.lotNumberList = _item;
        });
      } else {
        th.getCommonConfigByKey("药品剂量单位").then(res => {
          let l = res;
          let _item = [];
          for (let i = 0; i < l.length; i++) {
            let arr = {};
            for (let j = 0; j < th.list.length; j++) {
              if (l[i].id == th.list[j]) {
                arr = l[i];
                _item.push(arr);
              }
            }
          }
          th.lotNumberList = _item;
        });
      }
    },
    getUnit() {
      this.$emit("input", this.packUnit);
    }
  }
};
</script>